﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ThumbcacheHelper
{
    public enum CacheType
    {
        Thumbs32 = 0x00,
        Thumbs96 = 0x01,
        Thumbs256 = 0x02,
        Thumbs1024 = 0x03,
        ThumbsSR = 0x04,
        Unknown
    }

    public enum ImageType
    {
        UNKNOWN,
        BMP,
        JPG,
        PNG
    }

    public class EntryData
    {
        long dataSize;
        string fileName;
        string filePath;
        string dataChecksum;
        string headerChecksum;
        ImageType imgType;        
        byte[] thumbBytes;
        string srcFileName;

        public long Offset { get; set; }
        public string EntryHash { get; set; }
        public long DataSize { get { return dataSize; } set { dataSize = value; } }
        public string FileName { get { return fileName; } set { fileName = value; } }
        public string FilePath { get { return filePath; } set { filePath = value; } }
        public string DataChecksum { get { return dataChecksum; } set { dataChecksum = value; } }
        public string HeaderChecksum { get { return headerChecksum; } set { headerChecksum = value; } }
        public ImageType Type { get { return imgType; } set { imgType = value; } }        
        public string SourceFileName { get { return srcFileName; } set { srcFileName = value; } }
        public FileId FileId { get; set; }
        public long IdxOffset { get; set; }

        public void setThumbBytes(byte[] ThumbBytes)
        {
            thumbBytes = ThumbBytes;
        }

        public byte[] getThumbBytes()
        {
            return thumbBytes;
        }

        public EntryData()
        {
            Offset = -1;
            EntryHash = "unknown";
            dataSize = -1;
            dataChecksum = "unknown";
            headerChecksum = "unknown";
            fileName = "unknown";
            filePath = "unknown";
            imgType = ImageType.UNKNOWN;            
            thumbBytes = null;
            srcFileName = "unknown";
            IdxOffset = -1;
        }

        public string toCsv()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("{0},", Offset);
            sb.AppendFormat("{0},", EntryHash);
            sb.AppendFormat("{0},", dataSize);
            sb.AppendFormat("{0},", dataChecksum);
            sb.AppendFormat("{0},", headerChecksum);
            sb.AppendFormat("{0},", fileName);
            sb.AppendFormat("{0},", filePath);
            sb.AppendFormat("{0},", imgType);
            sb.Append(srcFileName);

            return sb.ToString();
        }
    }
}
